//
//  WBUserAccount.swift
//  XLWibo-Swift
//
//  Created by 王林 on 2016/11/15.
//  Copyright © 2016年 木木. All rights reserved.
//

import UIKit

class WBUserAccount: NSObject,NSCoding {

    //令牌
    var access_token : String?
    //到期时间
    var expires_in :Double = 0{
        didSet{
            espires_date = Date(timeIntervalSinceNow: expires_in)
        }
    }
    //过期的属性
    var espires_date :Date?
    //UID
    var uid :String?
    //友好显示名称
    var name :String?
    //用户头像地址
    var avatar_large :String?
    
    
    //MARK:
    // MARK: - kvc 赋值
    init(dict:[String:Any]) {
        super.init()
        setValuesForKeys(dict)
        
    }
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
    }
    
    //MARK:
    // MARK: - 解档
    
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        espires_date = aDecoder.decodeObject(forKey: "espires_date") as? Date
        uid = aDecoder.decodeObject(forKey: "uid") as? String
        name = aDecoder.decodeObject(forKey: "name") as? String
        avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as? String
    }
    
    //归档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(espires_date, forKey: "espires_date")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(name, forKey: "name")
        aCoder.encode(avatar_large, forKey: "avatar_large")
    }
    
    
}
